package cn.kooki.app.duobao.ui.Adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import butterknife.Bind;
import butterknife.ButterKnife;

import cn.kooki.app.duobao.R;
import cn.kooki.app.duobao.ui.widget.NumberPicker;
import cn.kooki.app.duobao.util.manager.ShopCartManager;

/**
 * Created by xiong on 2015/12/12.
 */
public class CartAdapter extends BaseAdapter {


    private boolean isEditing;

    public CartAdapter(boolean isEditing) {
        this.isEditing = isEditing;
    }

    public void setEditing(boolean editing) {
        isEditing = editing;
    }

    @Override
    public int getCount() {
        return ShopCartManager.getInstance().getCartsSize();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        ViewHolder viewHolder = null;
//        final GoodsItem item = ShopCartManager.getInstance().getItemAtPostion(position);
//        if (convertView == null) {
//            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_cart, parent, false);
//            viewHolder = new ViewHolder(convertView);
//            viewHolder.numberPicker.setTag(item.getId());
//
//            convertView.setTag(viewHolder);
//
//        } else {
//            viewHolder = (ViewHolder) convertView.getTag();
//        }
//        viewHolder.numberPicker.setChangerListener(new NumberPicker.OnNumberValueChangerListener() {
//            @Override
//            public void onChanged(int value) {
//
//                ShopCartManager.getInstance().changeCount(item.getId(), value);
//
//            }
//        });
//        viewHolder.numberPicker.setOnceCount(1);
//        int total = StringUtils.nullSafeParseInt(item.getZongrenshu());
//        int currt = StringUtils.nullSafeParseInt(item.getCanyurenshu());
//        viewHolder.numberPicker.setMaxCount(total - currt);
//        viewHolder.numberPicker.setCurrtCount(item.count);
//        viewHolder.name.setText(item.getTitle());
//        String numbertext = parent.getContext().getString(R.string.cart_progress_desc);
//        String formattext = String.format(numbertext, item.getZongrenshu(), total - currt);
//        viewHolder.progress.setText(formattext);
//        viewHolder.oneCheckbox.setVisibility(isEditing ? View.VISIBLE : View.GONE);
//        viewHolder.oneCheckbox.setSelected(ShopCartManager.getInstance().checkSelected(item.getId()));
        return convertView;
    }

    /**
     * This class contains all butterknife-injected Views & Layouts from layout file 'layout_cart.xml'
     * for easy to all layout elements.
     *
     * @author ButterKnifeZelezny, plugin for Android Studio by Avast Developers (http://github.com/avast)
     */
    static class ViewHolder {
        @Bind(R.id.one_checkbox)
        ImageButton oneCheckbox;
        @Bind(R.id.one_image)
        ImageView oneImage;
        @Bind(R.id.name)
        TextView name;
        @Bind(R.id.progress)
        TextView progress;
        @Bind(R.id.numberLabel)
        TextView numberLabel;
        @Bind(R.id.numberPicker)
        NumberPicker numberPicker;
        @Bind(R.id.regularBuyLabel)
        TextView regularBuyLabel;
        @Bind(R.id.regularBuyInput)
        TextView regularBuyInput;
        @Bind(R.id.hint)
        TextView hint;
        @Bind(R.id.goods_free_label)
        ImageView goodsFreeLabel;
        @Bind(R.id.good_ten_label)
        ImageView goodTenLabel;
        @Bind(R.id.limit_duobao_id)
        ImageView limitDuobaoId;
        @Bind(R.id.custom_top_left_icon)
        ImageView customTopLeftIcon;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
